﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

public partial class Manage_students : ManagePageBase {

    protected void Page_Load(object sender, EventArgs e) {
        btnSearch.Text = Resources.labels.search;
        if(!IsPostBack){
            BindDept();
            BindData();
        }
    }
    /// <summary>
    /// 绑定部门
    /// </summary>
    private void BindDept() {
        List<Exam.Core.Model.Department> Departlist = new Exam.Core.DAL.Department().getDepartmentAllList(isTheMe.DepartmentID.Trim());
        StringBuilder sb = new StringBuilder();
        foreach (Exam.Core.Model.Department obj in Departlist) {
            departddl.Items.Add(new ListItem(obj.DepartmentName.Trim(), obj.DepartmentID.Trim()));
            sb.Append(obj.DepartmentID.Trim() + ",");
            departddl2.Items.Add(new ListItem(obj.DepartmentName.Trim(), obj.DepartmentID.Trim()));
            departddl3.Items.Add(new ListItem(obj.DepartmentName.Trim(), obj.DepartmentID.Trim()));
            Editdepartddl2.Items.Add(new ListItem(obj.DepartmentName.Trim(), obj.DepartmentID.Trim()));
        }
        departddl.Items.Insert(0, new ListItem(Resources.labels.alldepartment, sb.ToString().Trim(',')));
    }
    /// <summary>
    /// 绑定考生
    /// </summary>
    private void BindData() {
        string departmentid = departddl.SelectedValue.Trim();
        string keyword = this.keywordTb.Text.Trim();
        int pagesize = AspNetPager1.PageSize;
        int page = AspNetPager1.CurrentPageIndex - 1; //GetPageIndex();
        int size = new Exam.Core.DAL.Student().getSize(
                departmentid,
                keyword);
        AspNetPager1.RecordCount = size;
        List<Exam.Core.Model.Student> list = new Exam.Core.DAL.Student().getStudentListByPage(
                pagesize,
                page,
                departmentid,
                keyword
            );
        rp.DataSource = list;
        rp.DataBind();

        LibStuCount.Text = size.ToString();
        LibStuCount.ForeColor = System.Drawing.Color.Blue;
    }
    protected string getDepart(string id){
        string result = "";
        int i = 0;
        foreach (ListItem item in departddl.Items) {
            //排除第一个
            //if (item.Text == "所有单位")
            if (i == 0) {
                i++;
                continue;
            }
            
            if (id.Trim() == item.Value.Trim()) {
                result = item.Text.Trim();
                break;
            }
        }
        return result.Trim();
    }

    protected void btnSearch_Click(object sender, EventArgs e) {
        BindData();
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e) {
        BindData();
    }
}
